package com.aurora.oa.message.presenter;


import android.util.Log;

import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.listener.OnRequestCompanyStructureDataListener;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.message.bean.ContactsDataJsonBean;
import com.aurora.oa.message.bean.ContactsGroupBean;
import com.aurora.oa.message.view.ContactsListActivity;
import com.aurora.oa.message.view.ContactsListActivityView;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.work.bean.CompanyStructureBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

/**
* Created by Administrator on 2017/03/24
*/

public class ContactsListActivityPresenterImpl implements ContactsListActivityPresenter{
    ContactsListActivityView mView;
    RequestHttpModel mModel = new RequestHttpModelImpl();
    public ContactsListActivityPresenterImpl(ContactsListActivityView contactsListActivity) {
        mView = contactsListActivity;
    }

   public void  getContanctsListData(){
       mModel.requestHttpDataString(AuroraConstants.GET_MY_CONTACTS_LIST_URL, new OnRequestHttpDataListener() {
           @Override
           public void onRequestDataSuccess(String body) {
               Log.e("log_date",body);
         //      {"msg":"查询成功","obj":[{"contactsList":[{"cgname":"得到的","groupid":"075356d539d54c21a6a6b8f5c425e18a","id":"15bd2017caf9447b8ad9f80bd720f0ba","linkman":"80e2c547767a40be80f109b02de0bbaa","name":"weir1","phone":"18200000000","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"得到的","groupid":"075356d539d54c21a6a6b8f5c425e18a","id":"1c1ace50740d42f1b00c752c95a1090a","linkman":"bbe717ffd1624034bab3fceee989f6c8","name":"test1","phone":"15233333333","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"得到的","groupid":"075356d539d54c21a6a6b8f5c425e18a","id":"d21178449f2645b18e72a05677f00a09","linkman":"4ec2d4f0bcfa4e85aa292f4470bd736a","name":"test2","phone":"15266666666","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"得到的","groupid":"075356d539d54c21a6a6b8f5c425e18a","id":"d7ff998a27584af9aa1c360583a57aac","linkman":"815c2802cff34d7292204d7af532aa45","name":"weir","phone":"18213410102","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"}],"id":"075356d539d54c21a6a6b8f5c425e18a","name":"得到的","remark":"","userid":"815c2802cff34d7292204d7af532aa45","username":""},{"contactsList":[{"cgname":"bk供货商","groupid":"22e814bc747f4601a4ed5499ef279bed","id":"c6aa7360a0e343f39c8bf8e843c0e62c","linkman":"12bbe4c4efc749759b88d46af5f64026","name":"测试用户D","phone":"18233333333","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"}],"id":"22e814bc747f4601a4ed5499ef279bed","name":"bk供货商","remark":"","userid":"815c2802cff34d7292204d7af532aa45","username":""},{"contactsList":[{"cgname":"市场人员","groupid":"3fbc920d2ff64aa3a0a19255bcdb47ab","id":"1","linkman":"bbe717ffd1624034bab3fceee989f6c8","name":"test","phone":"18212310101","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"市场人员","groupid":"3fbc920d2ff64aa3a0a19255bcdb47ab","id":"2","linkman":"4ec2d4f0bcfa4e85aa292f4470bd736a","name":"测试","phone":"15212310101","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"}],"id":"3fbc920d2ff64aa3a0a19255bcdb47ab","name":"市场人员","remark":"","userid":"815c2802cff34d7292204d7af532aa45","username":""},{"contactsList":[{"cgname":"东方 v 过","groupid":"b441aede2d774354a3ed58e49d394eb8","id":"38ec0a4d8dd845a99e72910a7e56d115","linkman":"80e2c547767a40be80f109b02de0bbaa","name":"weir1","phone":"18200000000","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"东方 v 过","groupid":"b441aede2d774354a3ed58e49d394eb8","id":"6c03a0482a984d688037852f7d6d1922","linkman":"4ec2d4f0bcfa4e85aa292f4470bd736a","name":"test2","phone":"15266666666","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"},{"cgname":"东方 v 过","groupid":"b441aede2d774354a3ed58e49d394eb8","id":"8b398671d46741309f012b5bf15d8684","linkman":"12bbe4c4efc749759b88d46af5f64026","name":"test3","phone":"18233333333","userHeadImage":"attachment/image/815c2802cff34d7292204d7af532aa45/20170411/files1491893757.png","userid":"815c2802cff34d7292204d7af532aa45","username":"weir"}],"id":"b441aede2d774354a3ed58e49d394eb8","name":"东方 v 过","remark":"","userid":"815c2802cff34d7292204d7af532aa45"

                   Gson gson = new Gson();
               Type type = new TypeToken<HttpResult<List<ContactsGroupBean>>>() {
               }.getType();
               HttpResult<List<ContactsGroupBean>> result =gson.fromJson(body,type);
               mView.showContanctsData(result.obj);
           }

           @Override
           public void onRequestDataFail(String message) {
              // mView.showErrorInfo(message);
           }
       });


    }

    @Override
    public void getStructureData() {
        mModel.getCompanyStructureData(new OnRequestCompanyStructureDataListener(){

            @Override
            public void onRequestCompanyStructureSuccess(List<CompanyStructureBean> companyStructureBeanList) {

            }

            @Override
            public void onRequestCompanyStructureFail(String message) {

            }
        });
    }
}